<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>

	<head>
	<link rel="shortcut icon" href="${ctx}/style/images/index/favicon.png" />
		<META http-equiv="X-UA-Compatible" content="IE=9" > </META> 
		<!-- 引入my97日期时间控件 -->
<script type="text/javascript" src="${ctx}/jslib/My97DatePicker/WdatePicker.js" charset="utf-8"></script>

<!-- 引入jQuery -->
<script src="${ctx}/jslib/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
<!-- 引入layer -->
<script src="${ctx}/jslib/layer/layer.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript" src="${ctx}/jslib/easyui1.3.3/jquery.easyui.min.js" charset="utf-8"></script>
 
<!-- 验证工具类 -->
<script type="text/javascript" src="${ctx}/jslib/biz/commonConverter.js" charset="utf-8"></script>
<!-- 扩展EasyUI图标 -->
<link rel="stylesheet" href="${ctx}/style/lightmvc.css" type="text/css">

		<link href="${ctx}/css/common.css" rel="stylesheet" type="text/css" />
		<link href="${ctx}/css/login.css" rel="stylesheet" type="text/css" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>用户登录</title>
		<script>
			var sessionInfo_userId = '${sessionInfo.id}';
			if(sessionInfo_userId) { //如果登录,直接跳转到index页面
				window.location.href = '${ctx}/admin/index';
			}
			$(function() {
				$("#loginname").focus();
			});
			$(function() {
				$(this).bind('keypress', function(event) {
					if(event.keyCode == "13") {
						submitForm();
					}
				});
				$('#loginname').bind('keypress', function(event) {
					if(event.keyCode == "13") {
						submitForm();
					}
				});
				$('#password').bind('keypress', function(event) {
					if(event.keyCode == "13") {
						submitForm();
					}
				});
				$('#loginform').form({
					url: '${ctx}/admin/login',
					onSubmit: function() {
						var index = layer.load(); //换了种风格
						var isValid = checkForm();
						if(!isValid) {
							layer.closeAll();
						}
						return isValid;
					},
					success: function(result) {
						result = $.parseJSON(result);
						layer.closeAll();
						if(result.success) {
							window.location.href = '${ctx}/admin/index';
						} else {
							layer.msg(result.msg);
						}
					}
				});
			});

			//获取公告信息
			$(function(){
				$.ajax({
					type:"get",
					url:'${ctx}/notice/noticePage?page=1&rows=10&temp='+Math.random(),
					dataType:'json',
					async:true,
					success:function(data) {
						var arr = data.rows;
						if (arr.length > 0) {
							for (var i = 0; i < arr.length; i++) {
								$("span[class='left'] > a").eq(i).text(CommonConverter.toNullString(arr[i].title)).attr("href","${ctx}/notice/outer/"+arr[i].id);
								$("span[class='right']").eq(i).text(CommonConverter.toNullString(arr[i].createTime));
							}
						}
					}
				});
			});

			function checkForm() {
				var loginname = $("#loginname").val();
				var password = $("#password").val();
				if(loginname == null || loginname == "") {
					layer.msg("请输入用户名");
					return false;
				}
				if(password == null || password == "") {
					layer.msg("密码不能为空");
					return false;
				}
				return true;
			}
			//			获取cookie值
			function getCookie(key) {
				var keyVals = document.cookie.split("; ");
				for(var i in keyVals) {
					//xxxx=xxxxx
					var kv = keyVals[i].split("=");
					if(kv[0] == key) {
						return kv[1];
					}
				}
				return null;
			};

			function submitForm() {
				var isSave = document.getElementById("rmbUser").checked;
				var username = document.getElementById("loginname").value;
				var pwd = document.getElementById("password").value;
				var d = new Date();
				d.setDate(d.getDate() + 10);
				if(isSave) {
					document.cookie = "username=" + username + ";expires=" + d;
					document.cookie = "pwd=" + pwd + ";expires=" + d;
				};
				$('#loginform').submit();
			};

			function clearForm() {
				$('#loginform').form('clear');
			};

			function GetPwdAndChk() {
				var usr = document.getElementById('loginname').value;
				var pwd = getCookie("pwd");
				if(pwd != null && usr==getCookie("username")) {
					document.getElementById("password").value = pwd;
				} else {
					document.getElementById("password").value= "";
				}
			};
		</script> 
	</head>

	<body>
				<div class="remindBox">
					<div class="remind1">登录</div>
				</div>
				<div class="navBox">
					<ul class="nav">
						<li><img src="${ctx}/image/nav1.gif"></li>
						<li class="specLi"><img src="${ctx}/image/nav2.gif"></li>
						<li class="specLi nav2"><img src="${ctx}/image/nav3.gif"></li>
					</ul>
				</div>
				<div class="bannerBox">
					<%-- <img src="${ctx}/image/banner.jpg" style="width:100%;height:420px;"/> --%>
					<div class="banner">
						<form id="loginform" method="post">
									<p class="text">用户登录</p>
									<p class="name"><input id="loginname" name="loginname" type="text"  onblur="GetPwdAndChk()"/></p>
									<p class="password"><input id="password" name="password" type="password" /></p>
									<input type="checkbox" id="rmbUser"/><span id="_crepassword">记住密码</span>
									<label><a id="register" href="${ctx}/user/regPage">立即注册</a></label>
							<div class="mynewBtn" onclick="submitForm()">登录</div>
						</form>
					</div>
				</div>
				<div class="bannerCBox">
					<ul class="bannerCenter">
						<li><img src="${ctx}/image/banner2.gif"/></li>
						<li><img src="${ctx}/image/banner3.gif"/></li>
						<li><img src="${ctx}/image/banner4.gif"/></li>
					</ul>
				</div>
				<div class="newsBox">
					<div class="news">
						<ul class="newsHeader">
							<li>热点公告<img src="${ctx}/image/news.gif"></li>
                            <li class="right"><a href="${ctx}/main/notice">查看更多</a></li>
						</ul>
						<ul class="newsContent">
							<li>
								<div class="left newsContent1"><span class="left"><a href="" target="_blank"></a></span><span class="right"></span></div>
								<div class="left newsContent1 newsContent2"><span class="left"><a href="" target="_blank"></a></span><span class="right"></span></div>
							</li>
							<li>
								<div class="left newsContent1"><span class="left"><a href="" target="_blank"></a></span><span class="right"></span></div>
								<div class="left newsContent1 newsContent2"><span class="left"><a target="_blank"></a></span><span class="right"></span></div>
							</li>
							<li>
								<div class="left newsContent1"><span class="left"><a href="" target="_blank"></a></span><span class="right"></span></div>
								<div class="left newsContent1 newsContent2"><span class="left"><a href="" target="_blank"></a></span><span class="right"></span></div>
							</li>
							<li>
								<div class="left newsContent1"><span class="left"><a href="" target="_blank"></a></span><span class="right"></span></div>
								<div class="left newsContent1 newsContent2"><span class="left"><a href="" target="_blank"></a></span><span class="right"></span></div>
							</li>
							<li>
								<div class="left newsContent1"><span class="left"><a href="" target="_blank"></a></span><span class="right"></span></div>
								<div class="left newsContent1 newsContent2"><span class="left"><a href="" target="_blank"></a></span><span class="right"></span></div>
							</li>
						</ul>
				  </div>
				</div>
	</body>

</html>